<template>
  <div class="container container_user">
    <div class="mod_user_header">
      <img src="/static/img/me_bg_pic.png" alt="" class="bg_user">
      <div class="user_avatar"><open-data type="userAvatarUrl" class="user_avatar_pic"></open-data></div>
      <div class="user_name"><open-data type="userNickName"></open-data></div>
    </div>

    <div class="mod_entrance_list">
      <!-- <div class="item">
        <img src="/static/img/icon_1.png" alt="" class="icon" />
        <div class="text">我的预约</div>
        <div class="iconfont icon-zsinto"></div>
      </div> -->
      <a class="item" hover-class="none" href="/pages/order-list/main">
        <img src="/static/img/icon_2.png" alt="" class="icon" />
        <div class="text">我的订单</div>
        <div class="iconfont icon-zsinto"></div>
      </a>
      <a class="item" hover-class="none" href="/pages/coupon-list/main">
        <img src="/static/img/icon_3.png" alt="" class="icon" />
        <div class="text">优惠券</div>
        <div class="iconfont icon-zsinto"></div>
      </a>
      <a class="item" hover-class="none" href="/pages/kefu/main">
        <img src="/static/img/icon_4.png" alt="" class="icon" />
        <div class="text">联系客服</div>
        <div class="iconfont icon-zsinto"></div>
      </a>
    </div>

    <div class="mod_box mod_box_related">
      <div class="mod_hd">
        <img src="/static/img/me_tuijian_title_left.png" alt="" class="d1">
        <div class="title">热门推荐</div>
        <img src="/static/img/me_tuijian_title_right.png" alt="" class="d2">
      </div>
      <div class="mod_bd">
        <div class="mod_grid_pic">
          <div class="grid_item"
                v-for="item in recListData"
                :key="item.goods_id"
                @click="gotoGoods(item)">
            <div class="figure">
              <img class="pic" :src="item.goods_img" alt="" />
            </div>
            <div class="title">{{item.goods_title}}</div>
            <div class="desc price" :class="{hidden: item.is_appointment == 1}">¥{{item.price}}</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import fly from '@/utils/fly'
import { reportData } from '@/utils/report'

export default {
  data () {
    return {
      isAuth: false,
      recListData: [],
      from: ''
    }
  },
  methods: {
    gotoGoods (item) {
      if (item.gt_id === 3) {
        wx.navigateTo({
          url: '/pages/detail/main?id=' + item.r_id
        })
      } else {
        wx.navigateTo({
          url: '/pages/goods-detail/main?id=' + item.goods_id
        })
      }
    }
  },
  async onLoad (options) {
    let that = this

    let res = await fly.post(`Goods/list?is_hot=1&limit=0,4`)
    if (res && res.code === 200 && res.data) {
      this.recListData = res.data.list
    }

    let scene = decodeURIComponent(options.scene || '')

    let _from = scene.replace('?', '').replace(/&id=\d+/, '').replace(/^id=\d+/, '')

    this.from = _from

    reportData({
      funcx: '我的-列表',
      keyx: '',
      from: this.from
    })
    this.from = ''

    // 查看是否授权
    wx.getSetting({
      success: function (res) {
        if (res.authSetting['scope.userInfo']) {
          // 已经授权，可以直接调用 getUserInfo 获取头像昵称
          wx.getUserInfo({
            success: function (res) {
              console.log(res.userInfo)
            }
          })
        } else {
          // 需要授权
          that.isAuth = false
          console.log('-- need user auth --')
        }
      }
    })
  }
}
</script>

<style lang="scss">
  @import './user.scss';
</style>
